package com.iwinding.ladygg.ui.act;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.iwinding.ladygg.R;
import com.iwinding.ladygg.event.AddFriendEvent;
import com.iwinding.ladygg.event.EventType;
import com.iwinding.ladygg.net.response.LoginRp;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

/**
 * Created by hezhiyong on 2017/4/6.
 */

public class AddFriendActivity extends BaseActivity implements View.OnClickListener {

    private View mSearch;
    private TextView mTvqrcode;
    LoginRp loginRp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe
    public void onEvent(AddFriendEvent event) {
        if (event.type == EventType.ADD_FRIEND) {
            finish();
        }
    }

    @Override
    protected int getLayoutID() {
        return R.layout.icane_activity_addfriends;
    }

    void initView() {
        setBackTxtResId(R.string.icane_contacts);
        setTitleResId(R.string.icane_add_friends);

        mSearch = findViewById(R.id.search);
        mTvqrcode = (TextView) findViewById(R.id.icane_tv_qr);

        mSearch.setOnClickListener(this);
        findViewById(R.id.icane_scan).setOnClickListener(this);
        findViewById(R.id.icane_mobile_directory).setOnClickListener(this);
        findViewById(R.id.icane_my_qrcode).setOnClickListener(this);

        loginRp = mOAAplication.getmLoginRp();
        String mobile = TextUtils.isEmpty(loginRp.mobile) ? "" : loginRp.mobile;
        mTvqrcode.setText(getString(R.string.icane_qr_code, mobile));

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.search:
                Intent search = new Intent(this, SearchActivity.class);
                startActivity(search);
                break;
            case R.id.icane_scan:
                Intent scan = new Intent(this, ScanActivity.class);
                startActivity(scan);
                break;
            case R.id.icane_mobile_directory:
                Intent mobile = new Intent(this, SysContactsActivity.class);
                startActivity(mobile);
                break;
            case R.id.icane_my_qrcode:
                Intent qr = new Intent(this, QrcodeActivity.class);
                qr.putExtra(QrcodeActivity.LASTACTNAME, getString(R.string.icane_add_friends));
                startActivity(qr);
                break;
        }
    }
}
